package com.lm.ChainOfResponsibility;

/**
 * 抽象日志类
 */
public abstract class AbstractLogger {

    public static final Integer INFO = 1;
    public static final Integer DEBUG = 2;
    public static final Integer ERROR = 3;

    protected Integer level;

    // 下一个责任链地址
    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger nextLogger){
        this.nextLogger = nextLogger;
    }

    public void logMessage(Integer level,String message){
        //判断当前日志级别是否小于设置的日志级别，小于等于则处理请求，大于则交由下一日志级别处理
        if(this.level <= level){
            write(message);
        }
        //判断是否存在下一日志级别
        if(nextLogger != null){
            nextLogger.logMessage(level,message);
        }
    }
    public abstract void write(String message);
}
